package com.rech.xbexpress3;

import android.os.Message;
import android.util.Log;

import com.rech.utils.CommandUtil;
import com.rech.utils.LogUtil;
import com.rech.utils.OtherUtil;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;

import java.util.List;
import java.util.Queue;

import static android.content.ContentValues.TAG;

public class RedisLogic {
    //private static String Domain = "http://app.yejianbao.com";//http://www.xmxbox.com";//http://app.yejianbao.com
    private static RedisLogic singletonRedisLogic = new RedisLogic();
    public static boolean redisWorking = false;
    //将构造器设置为private禁止通过new进行实例化
    private RedisLogic() {

    }
    public static RedisLogic getInstance() {
        return singletonRedisLogic;
    }

    public void doWorker(String recvCommand){
        if(recvCommand.length() == 0){
            return ;
        }

        try{
            JSONObject obj = new JSONObject(recvCommand);
            {
                int IO = obj.getJSONObject("data").getInt("IO");
                int _485 = obj.getJSONObject("data").getInt("485");
                obj.put("source","redis");
                obj.getJSONObject("data").put("status","1");//1 1a发送 2 1a发送确认 3 3a成功 4 3a成功确认 5 4a失败 6 4a失败确认 7 1c信息 8 1c信息确认
                String cmd = CommandUtil.toGetCommand(IO,_485);
                Log.d(TAG, "Command:"+cmd+"\n");
                LogUtil.getInstance().info(OtherUtil.getCurrentTime()+" REDIS:"+obj.toString());
                QueueService.send(cmd,obj,IO);

                Message msg1 = new Message();
                msg1.what = 8888;
                msg1.obj = cmd;
                EventBus.getDefault().post(msg1);
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }


    }
}
